<?php

class Core_Form_Admin_Settings_Cache extends Core_Form_Admin_Settings_Abstract
{
    public function init()
    {
        $this->setTitle('cache settings');
        $this->setDescription('core.form.admin.cache.desc');

        $this -> addElement('radio', 'cache_enable', array(
            'label' => 'use cache',
            'multiOptions' => array(
                'on' => 'yes, enable cache',
                'off' => 'no, disable cache'
            ),
            'description' => 'core.form.admin.usecache.desc',
            'value' => 'on',
            'required' => 1,
        ));

        // cache protocol.
        $this -> addElement('radio', 'cache_protocol', array(
            'label' => 'cache protocol',
            'multiOptions' => array(
                'file' => 'filebase cache',
                'apc' => 'apc cache',
                'memcache' => 'memcache, this is for multiple server - load balancing only.',
                'xcache' => 'xcache',
            ),
            'description' => 'core.form.admin.cache.protocol.desc',
            'value' => 'file',
            'required' => 1,
        ));

        // filebase path
        $this -> addElement('text', 'cache_file_path', array(
            'label' => 'path of cache path',
            'description' => 'core.form.admin.cache.file.path.desc',
            'value' => TEMP_PATH,
            'require' => 1,
            'class' => 'text long-text',
        ));

        //file locking for filebase cache protocol
        $this -> addElement('radio', 'cache_file_locking', array(
            'label' => 'file locking?',
            'description'=>'core.form.admin.cache.file.locking.desc',
            'multiOptions' => array(
                'on' => 'enable file locking',
                'off' => 'disable file locking',
            ),
            'value'=>'off',
        ));
        
        // mem cache host
        $this -> addElement('text', 'cache_mem_host', array(
            'label' => 'mem cache host',
            'description' => 'core.form.admin.cache.mem.host.desc',
            'class' => 'text long-text',
            'value' => '127.0.0.1',
        ));       
        
        
        // mem cache port
        $this -> addElement('text', 'cache_mem_port', array(
            'label' => 'mem cache port',
            'description' => 'core.form.admin.cache.mem.port.desc',
            'class' => 'text long-text',
            'value' => '11211',
            'validators'=>array('Int'),
        ));
        
        //file locking for filebase cache protocol
        $this -> addElement('radio', 'cache_mem_compress', array(
            'label' => 'mem cache compression?',
            'description'=>'core.form.admin.cache.mem.compress.desc',
            'multiOptions' => array(
                'on' => 'enable cache compress to save memory.',
                'off' => 'disable cache compress to save CPU time.',
            ),
            'value'=>'off',
        ));

        // cache life time sort
        $this -> addElement('select', 'cache_lifetime', array(
            'label' => 'cache lifetime',
            'value' => '300',
            'multiOptions' => array(
                '60' => '1 minute',
                '120' => '2 minutes',
                '180' => '3 minutes',
                '240' => '4 minutes',
                '300' => '5 minutes',
                '360' => '6 minutes',
                '420' => '7 minutes',
                '480' => '8 minutes',
                '540' => '9 minutes',
                '600' => '10 minutes'
            ),
            'class' => 'text long-text',
            'description' => 'core.form.admin.cache.lifetime.desc',
        ));

        // cache life time medium
        $this -> addElement('select', 'cache_lifetime_medium', array(
            'label' => 'cache lifetime medium',
            'value' => '3600',
            'multiOptions' => array(
                '600' => '10 minute',
                '1200' => '20 minutes',
                '1800' => '30 minutes',
                '2400' => '40 minutes',
                '3600' => '1 hour',
                '7200' => '2 hours',
                '10800' => '3 hours',
                '14400' => '4 hours',
            ),
            'class' => 'text long-text',
            'description' => 'core.form.admin.cache.lifetime.desc',
        ));

        // cache life time forever
        $this -> addElement('select', 'cache_lifetime_forever', array(
            'label' => 'cache lifetime forever',
            'value' => '28800',
            'multiOptions' => array(
                '3600' => '1 hour',
                '7200' => '2 hours',
                '14400' => '4 hours',
                '28800' => '6 hours',
                '75600' => '8 hours',
                '36000' => '10 hours',
                '43200' => '12 hours',
                '86400' => '1 day',
                '172800' => '2 days',
            ),
            'class' => 'text long-text',
            'description' => 'core.form.admin.cache.lifetime.desc',
        ));

        // init submit
        $this -> addElement('button', '_submit', array(
            'label' => 'save change',
            'type' => 'submit',
            'class' => 'submit',
            'decorators' => array('ViewHelper')
        ));
        
        // init submit
        $this -> addElement('button', '_cancel', array(
            'label' => 'cancel',
            'type' => 'submit',
            'class' => 'cancel',
            'decorators' => array('ViewHelper')
        ));

        $this -> addDisplayGroup(array(
            '_submit',
            '_cancel'
        ), '_buttons');
    }

}
